<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>审核列表(平台)</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '审核',
	        iconCls: 'icon-edit',
	        handler: function () {
                var row = $('#booklist').datagrid("getSelected");
                if (row == null) {
                    $.messager.alert('提示', '请先选择要修改的用户！', 'info');
                    return;
                }
	            $('#dd').dialog('open');}
	    }];
	   $(function(){
	       $('#booklist').datagrid({  
				title:'审核列表',
				iconCls:'icon-save',
				url:"/manager/examine/findByPage",
				columns:[
				    [
				    { field: 'id', title: '审核ID', width: '100', align: 'center' },
					{field:'title',title:'审核标题',width:100,align:'center'},
					{field:'info',title:'审核详情',width:200,align:'center'},
					{field:'flag',title:'审核状态',width:80,align:'center'},
                    {field:'bookid',title:'书籍详情',width:200,align:'center',formatter:function(value,row,index){
                            // return "<a href=''>查看</a>";
                            // console.log(111)
                            console.log(value);
                            // $("#echo-name").textbox("setValue",value);
                            return "<button type='submit' id='btn' onclick='openLook("+value+")'>查看书籍</button>";
                        }}
                ]
                ],
				toolbar: toolbar,  
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});

		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#dg').datagrid({ queryParams: form2Json("searchform") });   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        // alert("kkkkkkkkkk")
                        modifyExamine();
                        alert('ok');
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');
                    }
                }]
			});

           // 初始化回显窗口
           $('#echo').dialog({
               title: 'My Dialog',
               width: 700,
               height: 500,
               closed: true,
               cache: false,
               href: '',
               modal: true,
               iconCls: 'icon-save'
           });

           $('#supplier_type').combobox({
               method:'get',
               valueField:'id',
               textField:'name',
               panelHeight:'auto',
             });

           var list = [{'id': '', name: '全部','selected':true}];
           $.ajax({
               url:"/manager/supplier/findAll",
               method:'get',
               datatype: 'json',
               success: function (res) {
                   for (let a of res){
                       // console.log(type);
                       list.push({"id": a.id, "name": a.name });
                   }
                   $("#supplier_type").combobox("loadData", list);
               }
           })
	   });

	   function modifyExamine() {

           var row = $('#booklist').datagrid("getSelected");
           console.log(11111);
           // console.log(row.id);
           // console.log($("#info").val());
           // console.log($("#flag").val());
           console.log(row.supplierid)

           $.ajax({
               url: "/manager/examine/modifyExamine",
               data:{
                 id: row.id,
                   supplierid: row.supplierid,
                 info: $("#info").val(),
                 flag:$("#flag").val(),
                   bookid: row.bookid,
                   number: row.number

               },
               dataType: 'json',
               method: 'POST',
               cache: false,
               success: function (res) {
                   if (res.code == 200){
                       alert("上传文件成功!");
                       $('#articlelist').datagrid("reload");
                   }
               }
           });
       }
        function openLook(value){
            console.log("开始显示");
            console.log(value);
            $.ajax({
                url:"/manager/book/findById",
                data:{id: value},
                datatype: 'json',
                method: "get",
                success: function (res) {
                    if (res.code ==200){
                        console.log(111);
                        console.log(res.data.bookname, res.data.isbn,res.data.price);
                        $("#echo-bookname").textbox("setValue",res.data.bookname);
                        $("#echo-isbn").textbox("setValue",res.data.isbn);
                        $("#echo-price").textbox("setValue",res.data.price);
                        // $('#username_modify').textbox('setValue',result.data.username);
                        $("#echo-number").textbox("setValue",res.data.number);
                        $("#echo-groupprice").textbox("setValue",res.data.groupprice);
                        $("#echo-layout").textbox("setValue",res.data.layout);
                        $("#echo-register").textbox("setValue",res.data.register);
                        $("#echo-weight").textbox("setValue",res.data.weight);
                        $("#echo-bookintroduce").textbox("setValue",res.data.bookintroduce);
                        $("#echo-authorintroduce").textbox("setValue",res.data.authorintroduce);

                        console.log(res.data.imgurl);
                        $("#echo-image").attr("src","http://192.168.4.8:8080/"+res.data.imgurl);

                        // JS foreaxh取值，但需要值名字一一对应
                        // $.each(res.data,function(k,v){
                        //     $("#echo-"+k).textbox("setvalue",v);
                        // });

                        $('#echo').dialog('open');
                    }
                }
            })

        }

        function searchExamine() {
            var bookname = $("#bookname").val();
            var isbn = $("#isbn").val();
            // combobox取值需要通过.combobox("getValue")取值。
            var supplierid= $("#supplier_type").combobox("getValue");
            console.log(supplierid);
            // var supplierid = [[${session.id}]];
            $('#booklist').datagrid({
                queryParams:{
                    bookname, isbn, supplierid
                }
            });
        };
	</script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>审核查询：</strong></td>
    <td height="30">
        <input id="bookname" type="text" name="keyword" size=20 placeholder="书籍名称"/>
        <input id="isbn" type="text" name="keyword" size=20 placeholder="ISBN"/>

        <!--为什么改成jQuery页面会乱了？-->
        <!--labelAlign:'right',-->
        <!--<select id="supplier_type" class="easyui-combobox"style="width:200px;" data-options="label:'供应商：',labelWidth:70,panelHeight:'auto'"/>-->
        <!--search_type-->
        <select name="search_type" id="supplier_type" >
            <option value="">请选择供应商</option>
            <!--<option value="1" >供应商1</option>-->
            <!--<option value="1">供应商2</option>-->
            <!--<option value="1">供应商3</option>-->
        </select>

    </td>
	<td>
        <a id="standardQueryBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="searchExamine()">搜索</a>
	  <!--<button type="button" >查询</button>-->
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post"> 
             <table>
			    <tr>
				   <td>
				      审核状态:
				   </td>
				   <td>
						<select name="search_type" id="flag" style="width:100px">
							<option value="1">通过</option>
							<option value="-1">不通过</option>
						</select>
				   </td>
				</tr>
				<tr style="vertical-align:top">
				   <td>
				      审核详情:
				   </td>
				   <td>
				     <textarea id="info" rows="10" cols="30"></textarea>
				   </td>
				</tr>
			 </table>			
        </form>
           </div>
    </div>

   <div id="echo">
       <div align="center" style="margin-top: 30px">
           <form id="echoform" method="post">
               <div style="margin-bottom:20px">
                   <input id="echo-bookname" class="easyui-textbox" name="name" style="width:50%" data-options="label:'书籍名称:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-isbn" class="easyui-textbox" name="email" style="width:50%" data-options="label:'ISBN:',required:true,validType:'email'">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-price" class="easyui-textbox" name="email" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-number" class="easyui-textbox" name="email" style="width:50%" data-options="label:'数量:',required:true,validType:'email'">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-groupprice"class="easyui-textbox" name="subject" style="width:50%" data-options="label:'团购价:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-layout" class="easyui-textbox" name="subject" style="width:50%" data-options="label:'版次:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-register" class="easyui-textbox" name="subject" style="width:50%" data-options="label:'册数:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-weight" class="easyui-textbox" name="subject" style="width:50%" data-options="label:'重量:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-bookintroduce" class="easyui-textbox" name="message" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-authorintroduce" class="easyui-textbox" name="message" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
               </div>
               <div style="margin-bottom:20px">
                   封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input  type="file"/>
               </div>
               <div>
                   <img id="echo-image" src="" style='width:200px;'/>
               </div>
           </form>
       </div>
   </div>
</body>
</html>